class Product < ActiveRecord::Base
  attr_accessible :name, :price, :coupon_price, :description, :coupon_start_time, :coupon_end_time, :mall_id, :category_id, :commission, :commission_num, :image, :image_ids, :url, :tag_ids, :coupon_rate, :commission_rate

  belongs_to :mall, :inverse_of => :products
  belongs_to :category, :inverse_of => :products

  has_many :images, :inverse_of => :product

  has_and_belongs_to_many :tags


  rails_admin do
    list do
      field :image do
        pretty_value do
          ("<img src='" << bindings[:object].image << "' style='width:100px;'>").html_safe
        end
      end
      field :name do
        pretty_value do
          ("<a href='" << bindings[:object].url << "' target='_blank'>" << value.to_s << "</a>").html_safe
        end
      end
      field :price
      field :coupon_price
      field :coupon_rate do
        pretty_value do
          (value/100).to_s << '%'
        end
      end
      field :commission_rate do
        pretty_value do
          (value/100).to_s << '%'
        end
      end
      field :coupon_end_time
    end
  end
end
